{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    <script src="{{ path }}js/plugins/datatables/DT_bootstrap.js"></script>
	<script src="{{ path }}js/plugins/responsive-tables/responsive-tables.js"></script>
{% endblock %}

{% block jquery %}
        
        $( '#nuevo_formulario' ).click(function() {
            // alert("Hola mundo");
        });

        $( '#editar_formulario' ).click(function() {
            if($('input:checked').length == 1){
                return true;
            }
            if($('input:checked').length > 1){
                alert("Debe elegir sólo un formulario.");
                return false;
            }
            if($('input:checked').length < 1){
                alert("Debe seleccionar al menos un formulario.");
                return false;
            }
        });
        
        $( '#eliminar_formulario' ).click(function() {
            // funciones
        });

{% endblock %}   

{% block javascript %}
function OnSubmitForm()
{
	if(document.pressed == 'nuevo')
	{
		document.lista_formularios.action ="formulario_nuevo";
	}
	else
	if(document.pressed == 'editar')
	{
		document.lista_formularios.action ="formulario_editar";
	}
	else
	if(document.pressed == 'eliminar')
	{
		document.lista_formularios.action ="formulario_eliminar";
	}
	return true;
}

{% endblock %}


{% block ruta %}
		
{% endblock %}

{% block contenido %}
	<form id="lista_formularios" name="lista_formularios" onSubmit="return OnSubmitForm();" method="post">
    	{% csrf_token %}
        <div id="btn_formulario">
	        <input type="hidden" id="formulario" name="formulario" value="Hola mundo"/>
            <button type="submit" id="nuevo_formulario" value="nuevo" class="btn btn-medium" onclick="document.pressed=this.value">Crear formulario</button>
            <button type="submit" id="editar_formulario" value="editar" class="btn btn-medium" onclick="document.pressed=this.value">Editar formulario</button>
            <button type="submit" id="eliminar_formulario" value="eliminar" class="btn btn-medium" onclick="document.pressed=this.value">Eliminar formulario</button>
        </div>
        <br/>
        <table class="table table-striped table-bordered table-highlight" id="example">
            <thead>
                <tr>
                    <th width="5%"></th>
                    <th width="45%">Título</th>					
                    <th width="15%">Fecha Creación</th>
                    <th width="15%">Fecha Publicación</th>
                    <th width="15%">Fecha Vencimiento</th>
                    <th width="5%">Estado</th>
                </tr>
            </thead>
            <tbody>	
                {% for formulario in formularios %}
                <tr class="{% cycle '' 'odd' %}">
                    <td><input type="checkbox" id="chk_{{formulario.id}}" name="chk_{{formulario.id}}" value="true"/></td>
                    <td>{{ formulario.titulo }}</td>
                    <td style="text-align:center">{{ formulario.fecha_creacion }}</td>
                    <td style="text-align:center">{{ formulario.fecha_publicacion }}</td>
                    <td style="text-align:center">{{ formulario.fecha_vencimiento }}</td>
                    <td></td>
					<!--<td><a href="/empresa/editar_formulario"><img src="{{ path }}images/24x24/edit.png"/></a></td>-->
                </tr>
                {% endfor %}
            </tbody>
        </table>
	</form>
{% endblock %}